package com.nineclock.common.exception;

import com.nineclock.common.entity.Result;
import com.nineclock.common.enums.ResponseEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局异常拦截
 */
@ControllerAdvice
@ResponseBody
@Slf4j
public class BasicExceptionAdvice {
	  //捕获自定义异常 NcException
    @ExceptionHandler(NcException.class)
    public Result ncException(NcException e){
        e.printStackTrace();
        return Result.errorCodeMessage(e.getCode(),e.getMessage());
    }
	  //捕获其他异常
    @ExceptionHandler(Exception.class)
    public Result exception(Exception e){
        log.error(e.getMessage(),e);
        return Result.errorCodeMessage(ResponseEnum.SERVER_ERROR.getCode(), ResponseEnum.SERVER_ERROR.getMessage());
    }
	
}